/************************************************************************************
* YampConfig.h                                                                      *
*                                                                                   *
* Copyright (C) 2011 Varuna L Amachi                                                *
*                                                                                   *
* This program is free software; you can redistribute it and/or modify              *
* it under the terms of the GNU General Public License as published by              *
* the Free Software Foundation; either version 2 of the License, or any             *
* later version.                                                                    *
*                                                                                   *
* This program is distributed in the hope that it will be useful, but               *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY        *
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for       *
* more details. You should have received a copy of the GNU General Public           *
* License along with this program; if not, write to the Free Software Foundation,   *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                       *
*                                                                                   *
*************************************************************************************/

#ifndef YAMPCONFIG_H
#define YAMPCONFIG_H

/**
  Here's an Idea for whose implementation I dont have time now..
  Let's define set of settings type, say, color, font, boolean etc
  and come up with a format for each of these types to be stored in
  the database so that all these can be stored in a single table.
  Similar to serialization format which we can read back when we load
  the settings from the database. This config class will have the
  methods to get the setting in the class equivalant to that setting
  type, if there is an type missmatch there should be a graceful error.
  There should be methods to test the type conformance. I'll take this up
  later once other important things are done... this comment is just to
  remind me.
  */

#include <QHash>
#include <QSqlDatabase>

class YampConfig
{
private:

    QHash<QString, QVariant*> m_confMap;
    static YampConfig* __instance;
    YampConfig();
    void init();

public:
    static YampConfig* instance();

    void      addConfig(QString key, QVariant* value);
    void      addConfig(QString key, QString value);
    void      addConfig(QString key, int value);
    void      addConfig(QString key, double value);
    void      removeConfig(QString key);

    bool      hasConfig(QString key);
    QVariant *getConfig(QString key, QVariant* fallback = NULL);
    QString   getStringConfig(QString key, QString fallback = QString());
    int       getIntConfig(QString key, int fallback = -1);
    double    getDoubleConfig(QString key, double fallback = -1.0);

};

#endif // YAMPCONFIG_H
